from redis import Redis


class Rediscon:
    def __init__(self):
        self.r = Redis(host='localhost', port=6379, db=1)  # decode_responses=True

    # 存入数据
    def insertdata(self, key, *value):
        self.r.sadd(key, *value)

        # 取数据


    def getdata(self, key):
        res = self.r.smembers(key)
        if res:
            list=[]
            for i in res:
                list.append(str(i,encoding='utf8'))
            return list
        else:
            return None

    # hash 类型添加
    def insert_hash(self, key, params, value):  # key 相当于表名，params 相当于字段名，vaue是对应的值
        self.r.hset(key,params,value)


    # 获取某个值的属性
    def get_value_hash(self,key,params):
        self.r.hget(key,params)
    # 获取所有值的属性
    def get_all_hash(self,key):
        return self.r.hgetall(key)
    # 删除某个属性
    def del_hash(self,key,params):
        self.r.hdel(key,params)



rs = Rediscon()
